Module:If any equal/sandbox
Appearance
This is the module sandbox page for Module:If any equal (diff). |
This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
Usage
[edit]This module checks all positional parameters to see if any of them is equal to the parameter "value". If so, it will output "yes", otherwise "no".
Examples
[edit]{{#invoke:If any equal|main|a|b|c|d|value=c}}
gives yes{{#invoke:If any equal|main|a|b|c|d|value=r}}
gives no{{#invoke:If any equal|main|a|b|c|d|value=}}
gives no
require('strict')
local p = {}
p.main = function(frame)
local match = false
for pos, value in pairs(frame.args) do
if type(pos)=='number' and value:lower()==frame.args.value:lower() then
match = true
break
end
end
return match and 'yes' or 'no'
end
p.ifAnyEqual = function(frame)
local parent = frame:getParent()
if not parent.args then
return nil
end
local match = false
for pos, name in pairs(frame.args) do
if type(pos)=='number' and parent.args[name] and parent.args[name]:lower()==frame.args.value:lower() then
match = name
break
end
end
if match then
local suffix = frame.args.suffix
if suffix then
return parent.args[match..suffix]
else
return match
end
end
end
return p